# coding: UTF-8
# ----------
# Project_Name : pythonProject
# File_Name : huangcongbing
# Author : asus
# Date_Time:2022/4/26 15:39
# Description :
# ----------
import unittest  # 导入测试框架

from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait  # 导入显式等待类
from selenium.webdriver.support import expected_conditions  # 导入等待条件
from selenium.webdriver.common.action_chains import ActionChains


class zhyzptest(unittest.TestCase):  # 必须继承Tescase
    def setUp(self) -> None: #前置条件
        self.driver = webdriver.Chrome()
        self.wait = WebDriverWait(self.driver, 30)# 等待时间最多30秒
        self.driver.maximize_window()#  最大化窗口
        self.driver.get("http://192.168.2.6/cloud/#/my")  #打开网址

    def test(self):#  测试中
        self.wait.until(expected_conditions.visibility_of_element_located((By.XPATH, '//*[@id="account"]/input')))#显示等待
        self.driver.find_element(By.XPATH, '//*[@id="account"]/input').send_keys("admin")# 登录用户名输入”admin“

        self.driver.find_element(By.XPATH, '//*[@id="password"]/input').send_keys("123456")#输入密码

        self.driver.find_element(By.XPATH, '//*[@id="authCode"]/div/input').send_keys("8888")#万能验证码

        #self.wait.until(expected_conditions.visibility_of_element_located((By.XPATH, '//*[@id="root"]/div/div[1]/form/div[5]/div/div')))
        self.driver.find_element(By.XPATH, '//*[@id="root"]/div/div[1]/form/div[5]/div/div').click()# 点击登陆
        time.sleep(2)
        self.wait.until(expected_conditions.visibility_of_element_located(
            (By.XPATH, '//*[@id="root"]/section/aside/div/ul/li[3]')))
        self.driver.find_element(By.XPATH,'//*[@id="root"]/section/aside/div/ul/li[3]').click()#  点击人员管理
        #time.sleep(5)#调试时间

        self.wait.until(expected_conditions.visibility_of_element_located((By.XPATH, '//*[@id="system$Menu"]/li')))
        self.driver.find_element(By.XPATH,'//*[@id="system$Menu"]/li').click()#点击人员列表

        self.wait.until(expected_conditions.visibility_of_element_located(
            (By.XPATH,'//*[@id="root"]/section/section/main/div/div[1]/button[2]')))
        self.driver.find_element(By.XPATH,'//*[@id="root"]/section/section/main/div/div[1]/button[2]').click()#点击添加
        time.sleep(2)

        self.wait.until(expected_conditions.visibility_of_element_located((By.ID,'name')))
        self.driver.find_element(By.ID,'name').send_keys('胡啦') #添加的姓名


        self.driver.find_element(By.ID,'account').send_keys('hulai')#添加的账号
        self.driver.find_element(By.ID, 'pwd').send_keys('hulai123')  # 添加的密码
        self.driver.find_element(By.XPATH, '//*[@id="sex"]/div/div').click()  # 点击性别选项
        self.driver.find_element(By.XPATH,"//*[text()='男']").click()  # 点击男
        time.sleep(1)
        self.driver.find_element(By.XPATH, '//*[@id="cityComId"]').click()  # 点击绑定公司
        self.driver.find_element(By.XPATH, '//ul/li[text()="上海"]').click()  # 点击深圳
        self.driver.find_element(By.XPATH, '//ul/li[text()="中能上海"]').click()  # 点击深中能深圳
        els=self.driver.find_elements(By.CLASS_NAME, 'ant-select-selection__rendered') # 点击职位
        els[3].click()
        self.driver.find_element(By.XPATH, '//ul/li[text()="人事经理"]').click()  # 点击人事经理
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="cityId"]/div').click() #点击工作地址
        time.sleep(2)
        self.driver.find_elements(By.XPATH, '//ul/li[text()="上海"]')[1].click()  # 点击工作地址
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="phone"]').send_keys('15888888884') # 点击并输入电话号码
        self.driver.find_element(By.XPATH, '//*[@id="status"]/div/div').click()  # 点击工作状态
        self.driver.find_element(By.XPATH, "//ul/li[text()='允许']").click()  # 点击允许
        self.driver.find_element(By.ID, 'email').send_keys('1111122223@qq.com')  # 点击并输入电子邮箱
        self.driver.find_element(By.XPATH, '//*[@id="productId"]/div/div').click()  # 点击绑定产品
        self.driver.find_element(By.XPATH, "//*[text()='智慧社区管理系统']").click()  # 点击智慧社区管理系统
        self.driver.find_element(By.XPATH, '//*[@id="departmentId"]/div/div').click()  # 点击选择部门
        self.driver.find_element(By.XPATH, "//ul/li[text()='人事部']").click()  # 点击选择人事部
        time.sleep(1)
        self.driver.find_elements(By.CLASS_NAME,"ant-btn")[6].click()

    def testdown(self):
        self.driver.quit()